home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import horst.parser.HTMLDefs;
- import horst.parser.HTMLTags;
- import horst.parser.ParserCallback;
- import horst.parser.Tag;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.Toolkit;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.net.URL;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Stack;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import javax.swing.ComboBoxModel;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import javax.swing.JComboBox;
- import javax.swing.JComponent;
- import javax.swing.JList;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.Document;
-
- public class HTMLDocument implements ParserCallback {
- protected String m_title = "";
- protected Color m_linkColor;
- protected Color m_textColor;
- protected Color m_alinkColor;
- protected URL m_url;
- protected URL m_baseURL;
- protected TagStack m_tagStack;
- protected Stack m_characterStack;
- protected Element m_rootElement;
- protected Element m_baseElement;
- protected HTMLDocument m_thisDoc;
- protected String[] m_fontList;
- protected Object m_formModel;
- protected ComboBoxItem m_comboItem;
- protected boolean m_bInOption;
- protected boolean m_bInAnchor;
- protected boolean m_bInTextArea;
- protected boolean m_bInIFrame;
- protected boolean m_bInTitle;
- protected boolean m_bInPreformat;
- protected Vector m_relatedElements;
- protected Vector m_formProcessors;
- protected HTMLPane m_renderer;
- protected FormProcessor m_form;
- protected StringBuffer m_textbuffer;
- protected Vector m_mapElements;
- protected File m_sourceFile;
- protected URL m_refreshURL;
- protected Vector m_anchors;
- protected boolean m_bPrintTree;
- protected int m_selectedP0;
- protected int m_selectedP1;
- private static PrintWriter pwOut;
- private static int indent;
-
- public HTMLDocument(HTMLPane renderer) {
- this.m_linkColor = Color.blue;
- this.m_textColor = Color.black;
- this.m_alinkColor = Color.red;
- this.m_tagStack = new TagStack();
- this.m_characterStack = new Stack();
- this.m_bInOption = false;
- this.m_bInAnchor = false;
- this.m_bInTextArea = false;
- this.m_bInIFrame = false;
- this.m_bInTitle = false;
- this.m_bInPreformat = false;
- this.m_relatedElements = new Vector();
- this.m_formProcessors = new Vector();
- this.m_mapElements = new Vector();
- this.m_anchors = new Vector();
- this.m_bPrintTree = false;
- this.m_selectedP0 = -1;
- this.m_selectedP1 = -1;
- this.m_renderer = renderer;
- this.m_fontList = Toolkit.getDefaultToolkit().getFontList();
- this.m_bInOption = false;
- this.m_thisDoc = this;
- this.m_baseElement = new Element(53);
- this.m_textbuffer = new StringBuffer();
- }
-
- final void checkOptionContext() {
- if (this.m_bInOption && this.m_formModel instanceof DefaultComboBoxModel && this.m_comboItem != null) {
- ((DefaultComboBoxModel)this.m_formModel).addElement(this.m_comboItem);
- }
-
- }
-
- public static void closeLog() {
- if (pwOut != null) {
- pwOut.close();
- pwOut = null;
- }
-
- }
-
- protected TextAttributes createDefaultTextAttributes() {
- TextAttributes atts = new TextAttributes(this.m_renderer.m_props.m_defaultFont);
- atts.color = this.m_textColor;
- return atts;
- }
-
- protected void doStartElementTrap(Element elem) {
- int type = elem.getType();
- switch (type) {
- case 10:
- case 50:
- this.m_anchors.addElement(elem);
- break;
- case 39:
- String httpequiv = (String)elem.getAttribute("http-equiv");
- if (httpequiv != null && httpequiv.equalsIgnoreCase("Refresh")) {
- String content = (String)elem.getAttribute("content");
- if (content != null) {
- content = content.toLowerCase();
- int idx = content.indexOf("url=");
- if (idx >= 0) {
- String urlStr = content.substring(idx + 4).trim();
- this.m_refreshURL = Utilities.getURL(urlStr);
- }
- }
- }
- break;
- case 47:
- this.m_mapElements.addElement(elem);
- }
-
- }
-
- public Element findElement(int type, String attribute, String value) {
- return this.m_rootElement != null ? this.getElement(this.m_rootElement, type, attribute, value) : null;
- }
-
- public void finishedParsing() {
- if (this.m_rootElement != null) {
- int nChildCount = this.m_rootElement.getElementCount();
- if (nChildCount == 1) {
- this.m_rootElement = this.m_rootElement.getElementAt(0);
- } else {
- this.m_rootElement.m_type = 0;
- }
-
- this.m_rootElement.setDocument(this);
- if (this.m_rootElement.getType() != 0) {
- Element save = this.m_rootElement;
- this.m_rootElement = new Element(0);
- this.m_rootElement.addChild(save);
- }
-
- if (this.m_bPrintTree) {
- this.printTree(this.m_rootElement, 0);
- }
- }
-
- closeLog();
- }
-
- public Element getAnchor(String name) {
- Enumeration enum = this.m_anchors.elements();
-
- while(enum.hasMoreElements()) {
- Element elem = (Element)enum.nextElement();
- String val = (String)elem.getAttribute("name");
- if (val != null && val.equalsIgnoreCase(name)) {
- return elem;
- }
- }
-
- return null;
- }
-
- public Element[] getAnchors() {
- Element[] anchors = new Element[this.m_anchors.size()];
- this.m_anchors.copyInto(anchors);
- return anchors;
- }
-
- public Enumeration getAnchorsEnumeration() {
- return this.m_anchors.elements();
- }
-
- public Element getBaseElement() {
- return this.m_baseElement;
- }
-
- public URL getBaseURL() {
- return this.m_baseURL;
- }
-
- protected String getDefaultFontFace() {
- return this.m_renderer.m_props.m_defaultFont.getFamily();
- }
-
- protected int getDefaultFontSize() {
- return this.m_renderer.m_props.m_defaultFont.getSize();
- }
-
- protected Element getElement(Element e, int type, String attribute, String value) {
- if (e.getType() == type && e.isAttributeDefined(attribute) && ((String)e.getAttribute(attribute)).equals(value)) {
- return e;
- } else {
- int nChildren = e.getElementCount();
-
- for(int i = 0; i < nChildren; ++i) {
- Element result = this.getElement(e.getElementAt(i), type, attribute, value);
- if (result != null) {
- return result;
- }
- }
-
- return null;
- }
- }
-
- protected String getElementName(Element e) {
- return e.getName();
- }
-
- public Vector getFormProcessors() {
- return this.m_formProcessors;
- }
-
- public Color getLinkColor() {
- return this.m_linkColor;
- }
-
- public Element getMapElement(Element areaElem) {
- Enumeration enum = this.m_mapElements.elements();
-
- while(enum.hasMoreElements()) {
- Element elem = (Element)enum.nextElement();
- Vector v = elem.getChildren();
-
- for(int i = 0; i < v.size(); ++i) {
- if (v.elementAt(i) == areaElem) {
- return elem;
- }
- }
- }
-
- return null;
- }
-
- public Enumeration getMapElements() {
- return this.m_mapElements.elements();
- }
-
- public Element getRootElement() {
- return this.m_rootElement;
- }
-
- protected TextAttributes getTextAttributes(Tag t) {
- TextAttributes atts = null;
- if (!this.m_characterStack.empty()) {
- atts = new TextAttributes((TextAttributes)this.m_characterStack.peek());
- } else {
- atts = this.createDefaultTextAttributes();
- }
-
- return atts;
- }
-
- public StringBuffer getTextBuffer() {
- return this.m_textbuffer;
- }
-
- public Color getTextColor() {
- return this.m_textColor;
- }
-
- public String getTitle() {
- return this.m_title;
- }
-
- public URL getURL() {
- return this.m_url;
- }
-
- protected TextAttributes handleAnchor(Tag t, boolean bStart) {
- this.m_bInAnchor = bStart;
- TextAttributes atts = null;
- if (bStart) {
- atts = this.getTextAttributes(t);
- String href = (String)t.getAttribute("href");
- if (href != null) {
- atts.color = this.m_linkColor;
- atts.bUnderline = true;
- URL u = Utilities.getURL(this.m_baseURL, href);
- if (u != null) {
- atts.href = u.toString();
- } else {
- atts.href = href;
- }
- }
-
- String target = (String)t.getAttribute("target");
- if (target != null) {
- atts.target = target;
- }
-
- if (atts != null) {
- this.m_characterStack.push(atts);
- }
-
- this.handleBlockStart(t);
- } else {
- Element[] elems = new Element[this.m_relatedElements.size()];
- this.m_relatedElements.copyInto(elems);
- if (elems.length > 1) {
- for(int i = 0; i < elems.length; ++i) {
- Element currentElem = elems[i];
-
- for(int j = 0; j < elems.length; ++j) {
- if (currentElem != elems[j]) {
- elems[j].addRelatedElement(currentElem);
- }
- }
- }
- }
-
- if (elems.length > 0) {
- int sz = this.m_anchors.size();
- if (sz > 0) {
- Element currAnchor = (Element)this.m_anchors.elementAt(sz - 1);
-
- for(int j = 0; j < elems.length; ++j) {
- currAnchor.addRelatedElement(elems[j]);
- elems[j].m_anchor = currAnchor;
- }
- }
- }
-
- this.m_relatedElements.removeAllElements();
- if (!this.m_characterStack.empty()) {
- this.m_characterStack.pop();
- }
-
- this.handleBlockEnd(t);
- }
-
- return atts;
- }
-
- protected void handleBlockEnd(Tag t) {
- switch (t.getID()) {
- case 2:
- case 4:
- case 5:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- case 64:
- if (!this.m_characterStack.empty()) {
- this.m_characterStack.pop();
- }
- break;
- case 13:
- this.m_bInTitle = false;
- return;
- case 31:
- this.m_formModel = null;
- break;
- case 32:
- this.m_bInTextArea = false;
- this.m_formModel = null;
- break;
- case 54:
- this.checkOptionContext();
- this.m_bInOption = false;
- this.m_comboItem = null;
- break;
- case 67:
- this.m_bInIFrame = false;
- }
-
- if (!this.m_tagStack.empty()) {
- Element stackElem = (Element)this.m_tagStack.peek();
- if (stackElem.getType() == t.getID()) {
- this.m_tagStack.pop();
- } else {
- switch (t.getID()) {
- case 1:
- int[] tagIDs = new int[2];
- tagIDs[0] = 1;
- tagIDs[1] = 0;
- Element e = this.m_tagStack.getFirstElementType(tagIDs);
- if (e != null && e.getType() == 1) {
- this.m_tagStack.popElement(e);
- }
- break;
- case 3:
- case 5:
- case 8:
- case 12:
- if (stackElem.getType() == 6 && this.m_tagStack.size() > 1) {
- Element paraElem = (Element)this.m_tagStack.pop();
- stackElem = (Element)this.m_tagStack.peek();
- if (stackElem.getType() == t.getID()) {
- this.m_tagStack.pop();
- } else {
- this.m_tagStack.push(paraElem);
- }
- }
- case 6:
- break;
- default:
- Element e = this.m_tagStack.getElementType(t.getID());
- if (e != null) {
- this.m_tagStack.popElement(e);
- }
- }
- }
- }
-
- }
-
- protected void handleBlockStart(Tag t) {
- if (this.m_tagStack.empty() && t.getID() != 1 && t.getID() != 0) {
- this.m_rootElement = new Element(0);
- this.setBufferPointers(this.m_rootElement);
- this.m_tagStack.push(this.m_rootElement);
- }
-
- switch (t.getID()) {
- case 1:
- this.m_linkColor = Utilities.setColorProperty(Color.blue, "link", t.getAttributes());
- this.m_textColor = Utilities.setColorProperty(Color.black, "text", t.getAttributes());
- this.m_alinkColor = Utilities.setColorProperty(Color.red, "alink", t.getAttributes());
- break;
- case 2:
- case 5:
- this.m_characterStack.push(this.createDefaultTextAttributes());
- break;
- case 4:
- TextAttributes textAtts = this.createDefaultTextAttributes();
- textAtts.font = new Font(this.getDefaultFontFace(), 1, this.getDefaultFontSize());
- this.m_characterStack.push(textAtts);
- break;
- case 13:
- this.m_bInTitle = true;
- return;
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- this.handleHeadingStart(t);
- break;
- case 27:
- if (!this.m_tagStack.empty()) {
- Element stackElem = (Element)this.m_tagStack.peek();
- if (stackElem.getType() == 27) {
- this.m_tagStack.pop();
- }
- }
- break;
- case 30:
- Component c = Utilities.createFormComponent(this.m_thisDoc, t);
- if (c != null) {
- t.setAttribute("component", c);
- }
-
- if (this.m_form != null) {
- Element formElem = new Element(t.getID());
- this.setBufferPointers(formElem);
- formElem.setAttributes(t.getAttributesCopy());
- this.m_form.addComponent(formElem);
- }
- break;
- case 31:
- this.handleSelect(t);
- break;
- case 32:
- Component c = Utilities.createFormComponent(this.m_thisDoc, t);
- if (c != null) {
- this.m_formModel = ((JTextArea)c).getDocument();
- JScrollPane pane = new JScrollPane(c, 22, 32);
- t.setAttribute("component", pane);
- }
-
- this.m_bInTextArea = true;
- break;
- case 54:
- this.checkOptionContext();
- this.m_bInOption = true;
- this.m_comboItem = new ComboBoxItem(t);
- break;
- case 64:
- TextAttributes currentAtts = this.getTextAttributes(t);
- currentAtts.font = new Font("Serif", 2, 12);
- this.m_characterStack.push(currentAtts);
- break;
- case 67:
- if (!this.m_renderer.m_preferences.m_bIFramesEnabled) {
- return;
- }
-
- this.m_bInIFrame = true;
- }
-
- Element elem = new Element(t.getID());
- this.setBufferPointers(elem);
- elem.setDocument(this);
- elem.setAttributes(t.getAttributesCopy());
- this.setTextAttributes(elem);
- if (this.m_bInAnchor) {
- int sz = this.m_anchors.size();
- if (sz > 0) {
- Element anchor = (Element)this.m_anchors.elementAt(sz - 1);
- anchor.addRelatedElement(elem);
- }
- }
-
- int contextCheck = ContextChecker.checkContext(elem, this.m_tagStack, this.m_characterStack);
- if (contextCheck == 0) {
- this.doStartElementTrap(elem);
- if (!this.m_tagStack.empty()) {
- ((Element)this.m_tagStack.peek()).addChild(elem);
- }
-
- if (t.isBlockTag()) {
- if (this.m_tagStack.empty()) {
- this.m_rootElement = elem;
- }
-
- this.m_tagStack.push(elem);
- }
- }
-
- }
-
- protected void handleCharacterEnd(Tag t) {
- switch (t.getID()) {
- case 52:
- this.handleFont(t, false);
- break;
- default:
- if (!this.m_characterStack.empty()) {
- this.m_characterStack.pop();
- }
- }
-
- }
-
- protected void handleCharacterStart(Tag t) {
- TextAttributes currentAtts = this.getTextAttributes(t);
- int style = currentAtts.font.getStyle();
- switch (t.getID()) {
- case 28:
- case 56:
- case 57:
- currentAtts.font = new Font("Monospaced", 0, 12);
- break;
- case 38:
- case 60:
- style |= 2;
- currentAtts.font = new Font(currentAtts.font.getName(), style, currentAtts.font.getSize());
- break;
- case 40:
- case 42:
- style |= 1;
- currentAtts.font = new Font(currentAtts.font.getName(), style, currentAtts.font.getSize());
- break;
- case 41:
- currentAtts.font = new Font(currentAtts.font.getFamily(), currentAtts.font.getStyle(), currentAtts.font.getSize() - 1);
- break;
- case 48:
- currentAtts.font = new Font(currentAtts.font.getFamily(), currentAtts.font.getStyle(), currentAtts.font.getSize() + 1);
- break;
- case 52:
- case 72:
- currentAtts = this.handleFont(t, true);
- break;
- case 55:
- currentAtts.bUnderline = true;
- break;
- case 58:
- currentAtts.setAttribute("subscript", "true");
- break;
- case 59:
- currentAtts.setAttribute("superscript", "true");
- break;
- case 68:
- currentAtts.font = new Font("sansserif", 0, 12);
- break;
- default:
- return;
- }
-
- if (currentAtts != null) {
- this.m_characterStack.push(currentAtts);
- }
-
- }
-
- public void handleContent(StringBuffer buf) {
- if (this.m_bInTitle) {
- this.m_title = this.m_title + buf.toString();
- } else if (!this.m_bInIFrame) {
- if (this.m_bInOption && this.m_formModel != null) {
- if (this.m_formModel instanceof DefaultComboBoxModel && this.m_comboItem != null) {
- ComboBoxItem var10003 = this.m_comboItem;
- var10003.m_text = var10003.m_text + buf.toString();
- } else if (this.m_formModel instanceof DefaultListModel) {
- String s = buf.toString();
- if (!Utilities.isBlankSpaces(s)) {
- ((DefaultListModel)this.m_formModel).addElement(buf.toString());
- }
- }
- } else if (this.m_bInTextArea && this.m_formModel != null) {
- if (this.m_formModel instanceof Document) {
- Document d = (Document)this.m_formModel;
-
- try {
- d.insertString(d.getLength(), buf.toString(), (AttributeSet)null);
- } catch (BadLocationException var4) {
- }
- }
- } else {
- Element elem = new Element(9);
- this.setBufferPointers(elem, buf);
- elem.setDocument(this);
- this.setTextAttributes(elem);
- if (this.m_bInAnchor) {
- this.m_relatedElements.addElement(elem);
- }
-
- if (this.m_tagStack.empty()) {
- this.m_rootElement = new Element(0);
- this.setBufferPointers(this.m_rootElement);
- this.m_tagStack.push(this.m_rootElement);
- }
-
- Element e = (Element)this.m_tagStack.peek();
- e.addChild(elem);
- }
-
- }
- }
-
- protected TextAttributes handleFont(Tag t, boolean bStart) {
- TextAttributes currentAtts = this.getTextAttributes(t);
- String color = (String)t.getAttribute("color");
- if (color != null) {
- Color c = Utilities.stringToColor(color);
- if (c != null) {
- currentAtts.color = c;
- }
- }
-
- String face = currentAtts.font.getFamily();
- String value = (String)t.getAttribute("face");
- if (value != null) {
- value = value.toLowerCase();
- String fontName = this.getDefaultFontFace();
- StringTokenizer st = new StringTokenizer(value, ",");
-
- while(st.hasMoreTokens()) {
- String tok = st.nextToken().trim();
- if (tok.equals("arial")) {
- fontName = "sansserif";
- break;
- }
-
- if (this.haveFont(tok)) {
- fontName = tok;
- break;
- }
-
- if (tok.equals("courier") || tok.equals("monospaced")) {
- fontName = "courier";
- break;
- }
-
- if (tok.equals("helvetica")) {
- fontName = "sansserif";
- break;
- }
- }
-
- face = fontName;
- }
-
- int size = currentAtts.font.getSize();
- value = (String)t.getAttribute("size");
- if (value != null) {
- int fs = TextAttributes.getFontSize(this.getDefaultFontSize(), value);
- if (fs != -1) {
- size = fs;
- }
- }
-
- int style = currentAtts.font.getStyle();
- value = (String)t.getAttribute("style");
- int idx;
- if (value != null) {
- do {
- idx = value.indexOf(59);
- if (idx != -1 || idx == -1 && value.length() > 0) {
- String s;
- if (idx != -1) {
- s = value.substring(0, idx);
- } else {
- s = value;
- }
-
- int colonIndex = s.indexOf(58);
- if (colonIndex != -1) {
- String keyValue = null;
- String key = s.substring(0, colonIndex).trim();
- if (colonIndex != s.length() - 1) {
- keyValue = s.substring(colonIndex + 1).trim();
- }
-
- if (keyValue != null) {
- if (key.equalsIgnoreCase("font-size")) {
- int ptIdx = keyValue.indexOf("pt");
- if (ptIdx != -1) {
- try {
- size = Integer.parseInt(keyValue.substring(0, ptIdx));
- } catch (NumberFormatException var15) {
- }
- }
- } else if (key.equalsIgnoreCase("color")) {
- Color c = Utilities.stringToColor(keyValue);
- if (c != null) {
- currentAtts.color = c;
- }
- }
- }
- }
-
- if (idx != -1) {
- if (idx == value.length() - 1) {
- break;
- }
-
- value = value.substring(idx + 1);
- }
- }
- } while(idx != -1);
- }
-
- currentAtts.font = new Font(face, style, size);
- if (!bStart && !this.m_characterStack.empty()) {
- this.m_characterStack.pop();
- }
-
- return currentAtts;
- }
-
- protected void handleHeadingStart(Tag t) {
- TextAttributes currentAtts = this.getTextAttributes(t);
- String face = currentAtts.font.getFamily();
- int style = 1;
- int defaultSize = this.getDefaultFontSize();
- int size;
- switch (t.getID()) {
- case 14:
- size = defaultSize + 6;
- break;
- case 15:
- size = defaultSize + 4;
- break;
- case 16:
- size = defaultSize + 2;
- break;
- case 17:
- size = defaultSize;
- break;
- case 18:
- size = defaultSize - 1;
- break;
- case 19:
- size = defaultSize - 2;
- break;
- default:
- size = defaultSize;
- }
-
- currentAtts.font = new Font(face, style, size);
- this.m_characterStack.push(currentAtts);
- }
-
- public void handleNoBreakSpace() {
- if (!this.m_bInIFrame) {
- Element elem = new Element(101);
- this.setBufferPointers(elem);
- elem.setDocument(this);
- this.setTextAttributes(elem);
- if (this.m_bInAnchor) {
- this.m_relatedElements.addElement(elem);
- }
-
- if (!this.m_tagStack.empty()) {
- Element e = (Element)this.m_tagStack.peek();
- e.addChild(elem);
- }
-
- }
- }
-
- protected void handleSelect(Tag t) {
- JComponent c = null;
- Object var4;
- if (t.isAttributeDefined("multiple")) {
- this.m_formModel = new DefaultListModel();
- JList list = new JList((DefaultListModel)this.m_formModel);
- var4 = new JScrollPane(list);
- } else {
- this.m_formModel = new DefaultComboBoxModel();
- var4 = new JComboBox((ComboBoxModel)this.m_formModel);
- }
-
- t.setAttribute("component", var4);
- if (this.m_form != null) {
- Element e = new Element(t.getID());
- this.setBufferPointers(e);
- e.setAttributes(t.getAttributesCopy());
- this.m_form.addComponent(e);
- }
-
- }
-
- public void handleTag(Tag t, boolean bStartTag) {
- if (!this.m_bInIFrame || t.getID() == 67 && !bStartTag) {
- switch (t.getID()) {
- case 10:
- this.handleAnchor(t, bStartTag);
- break;
- case 28:
- this.m_bInPreformat = bStartTag;
- case 38:
- case 40:
- case 41:
- case 42:
- case 46:
- case 48:
- case 52:
- case 55:
- case 56:
- case 57:
- case 58:
- case 59:
- case 60:
- case 65:
- case 68:
- case 72:
- case 73:
- case 74:
- if (bStartTag) {
- this.handleCharacterStart(t);
- } else {
- this.handleCharacterEnd(t);
- }
- break;
- case 34:
- case 63:
- case 75:
- case 76:
- case 77:
- case 78:
- return;
- case 53:
- this.m_baseElement.setAttributes(t.getAttributesCopy());
- URL u = Utilities.setURLProperty((URL)null, "href", t.getAttributes());
- if (u != null) {
- this.m_baseURL = u;
- }
- default:
- if (bStartTag) {
- this.handleBlockStart(t);
- } else {
- this.handleBlockEnd(t);
- }
- break;
- case 66:
- if (bStartTag) {
- this.m_form = new FormProcessor(this.m_renderer, t.getAttributesCopy());
- } else if (this.m_form != null) {
- this.m_formProcessors.addElement(this.m_form);
- this.m_form = null;
- }
-
- return;
- }
-
- }
- }
-
- protected boolean haveFont(String face) {
- if (this.m_fontList != null) {
- for(int i = 0; i < this.m_fontList.length; ++i) {
- if (this.m_fontList[i].equalsIgnoreCase(face)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- public boolean isTextSelected() {
- return this.m_selectedP0 != -1 && this.m_selectedP1 != -1;
- }
-
- public void printDebugTree() {
- this.printTree(this.m_rootElement, 0);
- closeLog();
- }
-
- void printTree(Element e, int index) {
- String indent = "";
-
- for(int i = 0; i < index; ++i) {
- indent = indent + ' ';
- }
-
- String attStr = "";
- Hashtable atts = e.getAttributes();
- Enumeration enum = atts.keys();
-
- while(enum.hasMoreElements()) {
- Object key = enum.nextElement();
- Object value = atts.get(key);
- if (value != null) {
- attStr = attStr + " " + key + "=" + value;
- }
- }
-
- if (e.getType() == 9) {
- String style = "";
- Font f = e.getFont();
- if (f != null) {
- style = String.valueOf(f.getStyle());
- }
-
- String str = new String(e.getCharData());
- toLog(indent + this.getElementName(e) + " :x" + str + "x(" + attStr + ") style= " + style, 0);
- } else {
- toLog(indent + this.getElementName(e) + " (" + attStr + ")", 0);
- }
-
- index += 2;
-
- for(int i = 0; i < e.getElementCount(); ++i) {
- this.printTree(e.getElementAt(i), index);
- }
-
- }
-
- public void resetElements() {
- if (this.m_rootElement != null) {
- this.m_rootElement.reset();
- }
-
- }
-
- protected void setBufferPointers(Element elem) {
- int p0 = this.m_textbuffer.length();
- elem.setTextPointers(p0, p0);
- }
-
- protected void setBufferPointers(Element elem, StringBuffer buffer) {
- int p0 = this.m_textbuffer.length();
- char[] data = new char[buffer.length()];
- buffer.getChars(0, buffer.length(), data, 0);
- this.m_textbuffer.append(data);
- int p1 = this.m_textbuffer.length() - 1;
- elem.setTextPointers(p0, p1);
- }
-
- protected void setTextAttributes(Element elem) {
- TextAttributes atts = null;
- if (!this.m_characterStack.empty()) {
- atts = (TextAttributes)this.m_characterStack.peek();
- } else {
- atts = this.createDefaultTextAttributes();
- }
-
- atts.multiplexAttributes(elem);
- elem.m_focusColor = this.m_alinkColor;
- elem.setFont(atts.font);
- elem.m_bInPreformat = this.m_bInPreformat;
- }
-
- public void startingParsing(URL u) {
- this.m_url = u;
- this.m_baseURL = u;
- this.m_textbuffer.setLength(0);
- this.m_rootElement = new Element(100);
- this.m_tagStack.removeAllElements();
- this.m_tagStack.push(this.m_rootElement);
- this.m_renderer.notifyStatusListeners(1, this.m_baseURL);
- }
-
- public static void toLog(String str, int nIndent) {
- if (pwOut == null) {
- try {
- String dir = System.getProperty("user.dir");
- FileOutputStream fOut = new FileOutputStream(dir + "\\parser.log");
- pwOut = new PrintWriter(fOut);
- } catch (IOException e) {
- ((Throwable)e).printStackTrace();
- }
- }
-
- if (nIndent > 0) {
- indent += nIndent;
- }
-
- String identStr = "";
-
- for(int i = 0; i < indent; ++i) {
- identStr = identStr + " ";
- }
-
- pwOut.println(identStr + str);
- if (nIndent < 0) {
- indent += nIndent;
- }
-
- }
-
- public void unSelectText() {
- this.m_selectedP0 = -1;
- this.m_selectedP1 = -1;
- }
-
- protected void writeElement(HTMLTags tags, PrintWriter out, Element e, int nIndent) {
- String s = "";
- boolean bBlock = false;
- boolean bBreaksFlow = false;
- String name = HTMLDefs.getName(e.getType());
- if (name != null) {
- Tag t = tags.getTag(name);
- if (t != null) {
- bBlock = t.isBlockTag();
- bBreaksFlow = t.breaksFlow();
- }
- }
-
- if (bBlock || bBreaksFlow) {
- for(int i = 0; i < nIndent; ++i) {
- s = s + " ";
- }
-
- out.println("");
- }
-
- out.print(s + e.toString());
- nIndent += 4;
-
- for(int i = 0; i < e.getElementCount(); ++i) {
- Element elem = e.getElementAt(i);
- if (elem != null) {
- this.writeElement(tags, out, elem, nIndent);
- }
- }
-
- if (bBlock) {
- out.println("");
- out.println(s + "</" + e.getName() + ">");
- }
-
- }
-
- public void writeToStream(PrintWriter out) {
- if (this.m_rootElement != null) {
- this.writeElement(new HTMLTags(), out, this.m_rootElement, 0);
- }
-
- }
- }
-